<template>
  <div class="crumbs">
    <template v-if="crumbs_arr&&crumbs_arr.length>0">
      <header class="crumbs_arr_box">
        <span v-for="(_i,_in) in crumbs_arr" :key="_i.key" @click="router_change(_i,_in)">
          <i v-if="_in!==0"></i>
          {{_i.name}}
        </span>
      </header>
    </template>
    <template v-else>
      <header class="crumbs_arr_box">
        <span>{{default_name}}</span>
      </header>
    </template>
  </div>
</template>

<script>
export default {
  name: "crumbs", // 应用管理
  props: {
    crumbs_arr: Array, //  面包屑数组
    default_name: String // 接受默认标签
  },
  computed: {},
  methods: {
    router_change(obj, index) {
      let new_arr = [];
      this.crumbs_arr.map((_i, _in) => {
        if (_in <= index) {
          new_arr.push(_i);
        }
      });
      this.$store.commit("crumbs_arr_change", new_arr); //  更改面包屑数组
      if (obj.path) {
        this.$router.replace(obj.path); //  跳转页面
      }
    }
  }
};
</script>
<style scoped lang='scss'>
.crumbs {
  width: 100%;
}
// 面包屑样式
.crumbs_arr_box {
  cursor: pointer;
  width: 100%;
  padding-left: 40px;
  height: 44px;
  box-sizing: border-box;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 16px;
  font-weight: 600;
  line-height: 44px;
  span {
    text-align: center;
    display: flex;
    align-items: center;
  }
  i {
    display: inline-block;
    width: 2px;
    height: 18px;
    transform: rotate(20deg);
    background: #01b27a;
    margin: 0 16px;
  }
}
</style>
